<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
h2,
p {
    margin: 0;
}   
.box {
    margin: 30px auto;
    width: 300px;    
}
#user,
#message {
    box-sizing: border-box;
    width: 300px;
    border: 1px solid #000;
    padding: 10px;
    height: 100px;
    resize: none;
    display: block;
}
#user {
    padding: 0 10px;
    height: 30px;
    margin-bottom: 10px;
}
#btn {
    display: block;
    margin: 10px auto;
    width: 60%;
    height: 40px;
}
#list {
    border-top: 1px solid #000;
    padding: 10px 0 0;
    margin: 0;
    list-style: none;
}
#list li {
    position: relative;
    font: 14px/30px "宋体";
    border-bottom: 1px solid #000;
    padding: 0 15px;
    overflow: hidden;
}
.clos {
    position: absolute;
    right: 5px;
    top: 10px;
}
.clos2 {
    position: absolute;
    right: 5px;
    top: 30px;
}
.replay{
    position:absolute;
    right: 5px;
    top: 35px;
}
.mask{
    width: 100vw;
    height: 100vh;
    background: black;
    opacity: .3;
    position: absolute;
    left: 0;
    top: 0;
    display: none;
}
.comfirm{
    width: 200px;
    height: 120px;
    background: white;
    text-align: center;
    position: absolute;
    left: 50%;
    top: 30%;
    border-radius: 5px;
    transform: translate(-50%,-50%);
    overflow: hidden;
    display: none;
    
}
.comfirm button{
    float:right;
    margin-top: 20px;
    margin-right: 10px;
}

</style>
</head>
<body>
<div class="box">
    <input type="text" id="user" placeholder="输入用户名" />
    <textarea id="message" placeholder="在这里可以留下想说的话哦"></textarea>
    <button id="btn">提交留言</button>
    <h3>留言区:<h3>
    <ul id="list">
        
    </ul>
    
   
</div>
<script>
    // 直接写；
    var usernameEle = document.querySelector("#user");
    var contentEle = document.querySelector("#message");
    var btnELe = document.querySelector("#btn");
    var ulEle = document.querySelector("#list");

ulEle.innerHTML = "";
btnELe.onclick = function(){
    // document.querySelector("h2").style.display="none"
    var username = usernameEle.value;
    var replays = contentEle.value;
    
    var liEle = document.createElement("li");
    liEle.style.height = "auto";
    liEle.innerHTML = `<h2 class="user">${username}说:</h2>
                        <p class=>${replays}</p>
                        <a href="javascript:;" class="clos">删除</a>
                        <div class="reply" style="display:none">
                           <input type="text" />
                           <button class="sure">确定</button>
                           <button class="cancel">取消</button> 
                        </div>
                        <a href="javascript:;" class="clos2">回复</a>`;
    // 删除功能
    var delEle = liEle.querySelector(".clos");
    delEle.onclick = function(){
        this.parentNode.remove();
    }
    //回复
    var replyEleBtn=liEle.querySelector(".clos2");
    replyEleBtn.onclick=function(){
        this.style.display="none"
        this.previousElementSibling.style.display="block"
        //取消事件
        var cancelEle=liEle.querySelector(".cancel")
        cancelEle.onclick=function(){
            this.parentNode.style.display="none"
            this.parentNode.nextElementSibling.style.display="block"
        }
    }
    //确定键
    var replyText=liEle.querySelector(".reply");
    var sureBtn=liEle.querySelector(".sure")
    sureBtn.onclick=function(){
        //生成一个div 插在content之后
        this.parentNode.style.display="none"
        this.parentNode.nextElementSibling.style.display="block"//获取留言的时候 回复框隐藏， 留下回复的内容，并且回复按键继续出现
        var replayValue=document.createElement("div")
        replayValue.innerHTML=replyText.querySelector("input").value
        liEle.appendChild(replayValue);

    }
    ulEle.appendChild(liEle);
}
</script>
</body>
</html>